package net.jonbuck.tassoo.persistence.services;

import java.util.HashMap;
import java.util.Map;

import net.jonbuck.tassoo.persistence.dao.TassooDao;
import net.jonbuck.tassoo.persistence.dao.TassooDaoImpl;

import org.eclipse.ui.AbstractSourceProvider;
import org.eclipse.ui.ISources;

/**
 * 
 * 
 * @since 1.0.0
 */
public class TaskStoreState extends AbstractSourceProvider {

	private TassooDao tassooDao = TassooDaoImpl.getInstance();

	public static final String MY_STATE = "net.jonbuck.tassoo.persistence.resourceloaded";

	private static final String LOADED = "LOADED";

	private static final String UNLOADED = "UNLOADED";

	/**
	 * 
	 */
	public TaskStoreState() {
	}

	/**
	 * 
	 */
	public void dispose() {

	}

	/**
	 * 
	 */
	@SuppressWarnings("rawtypes")
	public Map getCurrentState() {
		Map<String, String> map = new HashMap<String, String>(1);
		if (tassooDao.isLoaded()) {
			map.put(MY_STATE, LOADED);
		} else {
			map.put(MY_STATE, UNLOADED);
		}
		return map;
	}

	/**
	 * 
	 */
	public String[] getProvidedSourceNames() {
		return new String[] { MY_STATE };
	}

	/**
	 * 
	 */
	public void checkState() {
		if (tassooDao.isLoaded()) {
			fireSourceChanged(ISources.WORKBENCH, MY_STATE, LOADED);
		} else {
			fireSourceChanged(ISources.WORKBENCH, MY_STATE, UNLOADED);
		}
	}

}
